<script type="text/javascript">
    (function($){
        $(document).ready(function() {
            $("#search_used").submit(function(e) {                
                var invalid_number = false;                
                var element_val = $("#maxprice_used").val();
                if(element_val != '') {            
                    var reg_number = /^[0-9]*$/;
                    if(!reg_number.test(element_val))
                        invalid_number = true;

                    var next_element = $("#maxprice_used").parent();
                    $(next_element).find('div.error').remove();
                }

                if(invalid_number) {
                    $("#maxprice_used").css('border-color', 'red');
                    $(next_element).append('<div class="error">Invalid number</div>');                        
                }
                else 
                    $(this).css('border', '1px solid #DADADA');

                if(invalid_number)
                    e.preventDefault();
            });        
        });
    })(jQuery);
</script>
<?php 
    echo form_open(base_url()."index.php/car/result", array('id'=>'search_used')); 
?>
<input type="hidden" name="cartype" value="used" />
<h1 class="red">Find Used Cars</h1>
<p>Make</p>
<p>
    <select class="form" name="make" id="make_used">
        <option value="">All Make</option>
<?php 
        foreach($make->result() as $row)
        { 
?>
        <option value="<?php echo $row->id; ?>">
<?php 
            echo $row->name; 
?>
        </option>
<?php
        }
?>        
    </select>
</p>
<p>Model</p>
<p>
    <select class="form" name="model" id="model_used">
        <option value="">All Model</option>      
    </select>
</p>
<p>Maximum Price</p>
<p>
    <input type="text" name="maxprice" class="number" id="maxprice_used" />
</p>
<p> Dealer </p>
<p>
    <select class="form" name="dealer" style="width: 260px;">
        <option value="">Please select</option>
<?php 
        foreach($dealer->result() as $row)
        { 
?>
        <option>
<?php 
            echo $row->company;
?>
        </option>
<?php
        }
?>    
    </select>
</p>
<p> Year </p>
<p>
    <select class="form" name="year">
        <option value="">Please select</option>
<?php 
            date_default_timezone_set("GMT");
            $current_year = date("Y");

            for($counter = $current_year; $counter >= $current_year - 62; $counter--)
            { 
?>
            <option>
<?php 
                //echo $row->year 
                echo $counter;
?>
            </option>
<?php
            }
?>    
    </select>
</p>
<p>Location</p>
<p>
    <select class="form" name="location">
        <option value="">Please select</option>
<?php 
        foreach($location->result() as $row)
        { 
?>
        <option>
<?php 
        echo $row->province; 
?>
        </option>
<?php
        }
?>    
    </select>
</p>
<?php 
    echo form_submit(array('name'=>'search', 'class'=>'btnsearchusecar'), '');
    echo form_close();
?>